/**
 *  @file SQLiteBlobIO.h
 */
#ifndef _SQLITEBLOBIO_H_
#define _SQLITEBLOBIO_H_

#include "../../common/BaseObject.h"
#include "../../text/CFString.h"
#include "../../collections/BinBuf.h"

namespace cppflib
{

namespace database
{

namespace sqlite
{

class SQLiteDatabase;

/**
 *  A class to directly read/write a blob cell inside a SQLite table
 *
 *  Note: The blob cell cannot be expanded automatically like writing a file
 */
class _DLLAPI SQLiteBlobIO : public BaseObject
{
private:
    SQLiteDatabase * pDB;
    ptrany_t blobHandle;

private:
    SQLiteBlobIO(void);

public:
    SQLiteBlobIO(SQLiteDatabase * pDB);
    virtual ~SQLiteBlobIO(void);

    bool Open(const CFString &dbName, const CFString &tabName, const CFString &blobColName, i64_t rowID, bool readOnly);
    bool Read(collections::BinBuf &binBuf, int binBufOffset, int blobOffset, int nrBytes);
    bool Write(const collections::BinBuf &binBuf, int binBufOffset, int blobOffset, int nrBytes);
    bool Reopen(i64_t anotherRowID);
    int GetBlobLength();
    void Close();
    
};

} // end of namespace sqlite

} // end of namespace database

} // end of namespace cppflib


#endif

